<table id="announcements_list" class="easyui-datagrid"
       fit="true" border="false"
       singleSelect="true" fitColumns="true" pagination="true" toolbar="#toolbar_announcements"
       idField="announcements_id" url="y.php?r=announcements/getdata">
    <thead>
    <tr>
        <th field="title" width="60">主题</th>
        <th field="announcements_type" width="60">公告类型</th>
        <th field="start_time" width="60">开始时间</th>
        <th field="end_time" width="60">结束时间</th>
    </tr>
    </thead>
</table>
<div id="toolbar_announcements">
    <?php
    if (Yii::app()->user->checkAccess('workspace_announcements_view')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-view',plain:true" onclick="announcements_view()" /a>
        <?php
    }
    if (Yii::app()->user->checkAccess('workspace_announcements_add')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="loadWin('添加公告','y.php?r=announcements/showedit&announcements_id=0')" /a>
        <?php
    }
    if (Yii::app()->user->checkAccess('workspace_announcements_edit')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="announcements_showedit()" />
        <?php
    }
    if (Yii::app()->user->checkAccess('workspace_announcements_remove')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="announcements_remove()" />
        <?php
    }
    ?>
</div>
<script>
    function announcements_showedit() {
        //获取选中的列
        var selected = $("#announcements_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            //进行编辑操作
            loadWin('添加公告','y.php?r=announcements/showedit&announcements_id='+selected.announcements_id);
        }
    }
    function announcements_remove() {
        var selected = $("#announcements_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r){
                    $.post('y.php?r=announcements/remove',{announcements_id:selected.announcements_id},function (res) {
                        $("#announcements_list").datagrid("reload");
                    });
                }
            });
        }
    }
    function announcements_view() {
        var selected = $("#announcements_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            loadWin('查看公告','y.php?r=announcements/view&announcements_id='+selected.announcements_id);
        }
    }
</script>
